package com.example.cursor_controller;

import com.example.cursor_service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/auth")
@Tag(name = "认证授权", description = "认证和授权相关的API接口")
public class AuthController {
    private final AuthService authService;
    
    @Autowired
    public AuthController(AuthService authService) {
        this.authService = authService;
    }
    
    @GetMapping("/check-permission")
    @Operation(summary = "检查用户权限", description = "检查用户是否拥有指定权限")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "权限检查完成")
    })
    public boolean checkUserPermission(@Parameter(description = "用户ID") @RequestParam Integer userId, 
                                     @Parameter(description = "权限名称") @RequestParam String permissionName) { 
        return authService.checkUserPermission(userId, permissionName); 
    }
    
    @GetMapping("/permissions")
    @Operation(summary = "获取用户权限列表", description = "获取用户的所有权限")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "获取权限列表成功")
    })
    public List<String> getUserPermissions(@Parameter(description = "用户ID") @RequestParam Integer userId) { 
        return authService.getUserPermissions(userId); 
    }
    
    @GetMapping("/check-role")
    @Operation(summary = "检查用户角色", description = "检查用户是否拥有指定角色")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "角色检查完成")
    })
    public boolean checkUserRole(@Parameter(description = "用户ID") @RequestParam Integer userId, 
                               @Parameter(description = "角色名称") @RequestParam String roleName) { 
        return authService.checkUserRole(userId, roleName); 
    }
    
    @GetMapping("/roles")
    @Operation(summary = "获取用户角色列表", description = "获取用户的所有角色")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "获取角色列表成功")
    })
    public List<String> getUserRoles(@Parameter(description = "用户ID") @RequestParam Integer userId) { 
        return authService.getUserRoles(userId); 
    }
} 